package com.sumainfor.pc.market.service;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.JsonObject;
import com.sumainfor.common.Constants;
import com.sumainfor.common.util.Arith;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.*;
import com.sumainfor.pc.market.dao.CommunityMapper;
import com.sumainfor.pc.market.dao.OwnerMapper;
import com.sumainfor.pc.market.dao.ProfitMapper;
import com.sumainfor.pc.market.dao.UtilsMapper;
import com.sumainfor.pc.market.feign.EpcFeign.EpcFeign;
import com.sumainfor.pc.market.feign.ZuulFeign.ZuulFeign;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.*;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 功能描述:
 * 盈利预测
 * @Auther: zhlu
 * @Date: 2018/11/24 17:08
 * @Description:
 */
@Service
public class ProfitService {
    private ReentrantLock lock = new ReentrantLock(false);
    Logger log= LoggerFactory.getLogger(CommunityService.class);
    String UUID=null;

    @Autowired
    private UtilsMapper utilsMapper;

    @Autowired
    private  ProfitMapper profitMapper;

    @Autowired
    OwnerMapper ownerMapper;

    @Autowired
    ZuulFeign ZuulFeign;

    @Autowired
    EpcFeign EpcFeign;

    @Autowired
    CommunityMapper CommunityMapper;

    String OwDeId=null;

    String ProCheck=null;

    /**
     * 功能描述:
     * 新增盈利预测
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/11/24 17:29
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean AddProfit(Map<String,Object> params){
        boolean result=false;
        /**
         * 加锁操作
         */
        lock.lock();
        try {
            Map<String,Object>uuid=utilsMapper.getUUID(new HashMap<String,Object>(){{
                put("uuid", "ProId");
                put("database", Constants.DATA_SOURCE_TCMKT);
                put("surface", "tcmkt_profit");
            }});
            if(uuid!=null){
                int number=Integer.valueOf(uuid.get("uuid").toString());
                UUID= ComUtils.getLocalTrmSeqNum("yl",number);
            }else{
                UUID=ComUtils.getLocalTrmSeqNum("yl",0);
            }
            //所有新增处理
            Map<String,Object>commonInsertParms=new HashMap<String,Object>();
            commonInsertParms.put("by", ContextUtils.getUserId());//操作人
            commonInsertParms.put("ProId",UUID);//项目编号等于项目名称加路号
            commonInsertParms.put("term", "2");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
            commonInsertParms.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(commonInsertParms);

            params.putAll(commonInsertParms);

            //所有修改处理
            Map<String,Object>commonUpdateParms=new HashMap<String,Object>();
            commonUpdateParms.put("by", ContextUtils.getUserId());//操作人
            commonUpdateParms.put("term", "2");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
            commonUpdateParms.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonUpdateParms(commonUpdateParms);
            params.putAll(commonUpdateParms);
            try {
                //收房人编号（收房专员）
                params.put("HouseId",ContextUtils.getUserId());
                //新增盈利预测主表
                profitMapper.AddProfit(params);
                //修改业主资料
                ownerMapper.UpdateOwner(params);

                Map<String,Object>message=new HashMap<String,Object>();
                message.put("MeType","2");//市场部经理
                message.put("Title","新的待审核盈利表");
                message.put("Content", HtmlUtil.stringToHTML("注意！您有一份新的盈利预测表待审核，请及时处理！",null,null));
                message.put("by",ContextUtils.getUserId());//操作人
                message.put("term","2");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                //新增消息
                ZuulFeign.AddMessage(message);

                //完整盈利预测
                if(params.get("ProType").equals(1)||params.get("ProType")=="1"){
                    //新增盈利预测详表
                    profitMapper.AddProfitInfo(params);
                    //新增盈利预测招租推广费用
                    List<Map<String, Object>> ProfitLet = (List<Map<String, Object>>) params.get("ProfitLet");
                    for(Map<String, Object> let:ProfitLet){
                        let.putAll(commonInsertParms);
                        profitMapper.AddProfitLet(let);
                    }

                    //新增盈利预测计算结果列表
                    List<Map<String, Object>> ProfitCal = (List<Map<String, Object>>) params.get("ProfitCal");
                    for(Map<String,Object> cal:ProfitCal){
                        cal.putAll(commonInsertParms);
                        profitMapper.AddProfitCal(cal);
                    }

                    //新增盈利预测计算结果列表详情
                    List<Map<String, Object>> ProfitCalInfo = (List<Map<String, Object>>) params.get("ProfitCalInfo");
                    for(Map<String, Object> calinfo:ProfitCalInfo){
                        calinfo.putAll(commonInsertParms);
                        profitMapper.AddProfitCalInfo(calinfo);
                    }

                    //新增盈利预测-每年收房方式成本
                    List<Map<String, Object>> CostPerCost = (List<Map<String, Object>>) params.get("CostPerCost");
                    for(Map<String, Object> cost:CostPerCost){
                        cost.putAll(commonInsertParms);
                        profitMapper.AddProfitCalHou(cost);
                    }
                }

                Map<String,Object>proCheck=utilsMapper.getUUID(new HashMap<String,Object>(){{
                    put("uuid", "ProCheck");
                    put("database", Constants.DATA_SOURCE_TCMKT);
                    put("surface", "tcmkt_profit_check");
                }});
                if(proCheck!=null){
                    int number=Integer.valueOf(proCheck.get("uuid").toString());
                    ProCheck= ComUtils.getLocalTrmSeqNum("ylsk",number);
                }else{
                    ProCheck=ComUtils.getLocalTrmSeqNum("ylsk",0);
                }

                //盈利预测审核对象
                Map<String,Object>check=new HashMap<String,Object>();
                check.put("ProCheck",ProCheck);
                check.put("SubmitId",ContextUtils.getUserId());
                check.put("SubmitTime", ConvertDateTime.getCurrentTime());
                check.putAll(commonInsertParms);
                //新增盈利预测审核记录
                profitMapper.AddProfitCheck(check);

                //把当前盈利预测审核记录标记为最新的
                profitMapper.updateProfit(new HashMap<String,Object>(){{
                    put("ProCheck",check.get("ProCheck"));
                    put("ProId",check.get("ProId"));
                }});

                result=true;
            } catch (Exception e) {
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }

        } finally {
            lock.unlock();
        }
        return result;
    }

    /**
     * 功能描述:
     * 根据类型获取盈利预测列表。ProState 状态   1草稿  2待审核
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/2 14:12
     */
    public List<Map<String,Object>>ProfitList(Map<String,Object> params){
        List<Map<String,Object>> ProfitList=profitMapper.ProfitList(params);
        for(Map<String,Object> map:ProfitList){
            if(!StringUtils.isBlank(MapUtils.getString(map,"BuilDing"))){
                if(StringUtils.isBlank(MapUtils.getString(map,"Room"))){
                    map.put("BuilDingRoom",map.get("BuilDing").toString()+"号");
                }else{
                    map.put("BuilDingRoom",map.get("BuilDing").toString()+"号"+map.get("Room").toString()+"室");
                }
            }else{
                map.put("BuilDingRoom",null);
            }

            if(!StringUtils.isBlank(MapUtils.getString(map,"OwLoculus"))){
                if(!StringUtils.isBlank(MapUtils.getString(map,"OwHall"))){
                    if(!StringUtils.isBlank(MapUtils.getString(map,"OwGuard"))){
                        map.put("house",map.get("OwLoculus").toString()+"室"+map.get("OwHall").toString()+"厅"+map.get("OwGuard").toString()+"卫");
                    }else{
                        map.put("house",map.get("OwLoculus").toString()+"室"+map.get("OwHall").toString()+"厅");
                    }
                }else{
                    map.put("house",map.get("OwLoculus").toString()+"室");
                }
            }else{
                map.put("house",null);
            }
        }
        return ProfitList;
    }

    /**
     * 功能描述:
     * 根据类型获取盈利预测列表总数。ProState 状态   1草稿  2待审核
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/2 14:13
     */
    public Integer ProfitListCount(Map<String,Object> params){
        int ProfitListCount=profitMapper.ProfitListCount(params);
        return ProfitListCount;
    }

    /**
     * 功能描述:
     * 根据编号获取盈利预测表
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/3 15:04
     */
    public Map<String,Object>getProfitMap(Map<String,Object>params){
        //盈利预测详情
        Map<String,Object>getProfitMap=profitMapper.getProfitMap(params);
        Map<String,Object>Citys=new HashMap<String,Object>();
        Citys.put("Province",getProfitMap.get("Province"));
        Citys.put("City",getProfitMap.get("City"));
        Citys.put("District",getProfitMap.get("District"));
        Citys.put("Street",getProfitMap.get("Street"));
        getProfitMap.put("Citys",Citys);
        //盈利预测招租推广费用
        List<Map<String,Object>>getProfitLetList=profitMapper.getProfitLetList(params);
        getProfitMap.put("ProfitLet",getProfitLetList);
        //盈利预测计算结果列表
        List<Map<String,Object>>getProfitCalList=profitMapper.getProfitCalList(params);
        List<Map<String,Object>>ProfitCal1=new ArrayList<Map<String,Object>>();
        List<Map<String,Object>>ProfitCal2=new ArrayList<Map<String,Object>>();
        List<Map<String,Object>>ProfitCal3=new ArrayList<Map<String,Object>>();
        if(!getProfitCalList.isEmpty()){
            for(Map<String,Object> map:getProfitCalList){
                HashMap<String, Object> item = Maps.newHashMap(map);
                if(item.get("CalType").equals(1)){
                    ProfitCal1.add(item);
                }else if(item.get("CalType").equals(2)){
                    ProfitCal2.add(item);
                }else if(item.get("CalType").equals(3)){
                    ProfitCal3.add(item);
                }
            }
        }
        getProfitMap.put("ProfitCal1",ProfitCal1);
        getProfitMap.put("ProfitCal2",ProfitCal2);
        getProfitMap.put("ProfitCal3",ProfitCal3);
        getProfitMap.put("ProfitCal",getProfitCalList);
        //盈利预测-计算结果
        List<Map<String,Object>>getProfitCalInfo=profitMapper.getProfitCalInfo(params);

        List<Map<String,Object>>ProfitCalInfo1=new ArrayList<Map<String,Object>>();
        List<Map<String,Object>>ProfitCalInfo2=new ArrayList<Map<String,Object>>();
        List<Map<String,Object>>ProfitCalInfo3=new ArrayList<Map<String,Object>>();

        if(getProfitCalInfo.size()>0){
            if(!getProfitCalInfo.isEmpty()){
                for(Map<String,Object> map:getProfitCalInfo){
                    HashMap<String, Object> item = Maps.newHashMap(map);
                    if(FieldCheckUtil.isMapFieldNotNull(item,new String[]{"CalType"})){
                        if(item.get("CalType").equals(1)){
                            ProfitCalInfo1.add(item);
                            getProfitMap.put("ProfitCalInfo1",item);
                        }else if(item.get("CalType").equals(2)){
                            ProfitCalInfo2.add(item);
                            getProfitMap.put("ProfitCalInfo2",item);
                        }else if(item.get("CalType").equals(3)){
                            ProfitCalInfo3.add(item);
                            getProfitMap.put("ProfitCalInfo3",item);
                        }
                    }
                }
            }
            getProfitMap.put("ProfitCalInfo",getProfitCalInfo);
        }
        List<Map<String,Object>>getProfitHou=profitMapper.getProfitHou(params);
        getProfitMap.put("CostPerCost",getProfitHou);
        log.info("getProfitMap------>>>>"+ JSONObject.toJSONString(getProfitMap));
        return getProfitMap;
    }

    /**
     * 功能描述:
     * 修改盈利预测表状态   状态   1草稿  2待审核  3驳回   4审核通过  5放弃（失效）
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/6 10:29
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean updateProfit(Map<String,Object>params){
        boolean result=false;
        Map<String,Object> updateParms=new HashMap<String,Object>();

        Map<String,Object>message=new HashMap<String,Object>();
        updateParms.put("by",ContextUtils.getUserId());//操作人
        updateParms.put("term", "2");// 更新端 Update端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
        updateParms.put("fnc",
                this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
        ParamsCommon.commonUpdateParms(updateParms);
        //所有新增处理
        Map<String,Object>commonInsertParms=new HashMap<String,Object>();
        commonInsertParms.put("by", ContextUtils.getUserId());//操作人
        commonInsertParms.put("ProId",params.get("ProId"));//项目编号等于项目名称加路号
        commonInsertParms.put("term", "2");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
        commonInsertParms.put("fnc",
                this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
        ParamsCommon.commonInsertParms(commonInsertParms);

        try {
            //是否需要修改其他值。0不需要。1需要 默认不需要，只需要修改状态就好
            if(params.get("IfUpdate").equals(0)){
                //状态   状态   1草稿  2待审核  3驳回   4审核通过  5放弃（失效）  6房源收录草稿箱  7房源收录成功
                if(params.get("ProState").equals(4)||params.get("ProState").toString()=="4"){
                    //获取合同最新id
                    Map<String,Object>owDeId=utilsMapper.getUUID(new HashMap<String,Object>(){{
                        put("uuid", "OwDeId");
                        put("database", Constants.DATA_SOURCE_TCMKT);
                        put("surface", "tcmkt_owner_deal");
                    }});
                    if(owDeId!=null){
                        int number=Integer.valueOf(owDeId.get("uuid").toString());
                        OwDeId= ComUtils.getLocalTrmSeqNum("yzht",number);
                    }else{
                        OwDeId=ComUtils.getLocalTrmSeqNum("yzht",0);
                    }
                    //审核人编号
                    params.put("Reviewer",ContextUtils.getUserId());
                    params.put("OwDeId",OwDeId);
                    params.putAll(commonInsertParms);
                    //审核通过之后新增业主合同
                    ownerMapper.AddOwnerDeal(params);

                    //修改业主资料,保存最新业主合同
                    ownerMapper.UpdateOwner(new HashMap<String,Object>(){{
                        put("OwId",params.get("OwId"));
                        put("OwDeId",OwDeId);
                    }});

//                    message.put("MeType","1");//收房专员
//                    message.put("Title","有新的表单通过");
//                    message.put("Content", HtmlUtil.stringToHTML("恭喜！您申请的盈利预测表已审核通过！请完成收房。",null,null));

                }
//                else if(params.get("ProState").equals(2)||params.get("ProState").toString()=="2"){
//                    message.put("MeType","2");//市场部经理
//                    message.put("Title","新的待审核盈利表");
//                    message.put("Content", HtmlUtil.stringToHTML("注意！您有一份新的盈利预测表待审核，请及时处理！",null,null));
//                }
//                else if(params.get("ProState").equals(3)||params.get("ProState").toString()=="3"){
//                    message.put("MeType","1");//收房专员
//                    message.put("Title","有表单被驳回");
//                    message.put("Content", HtmlUtil.stringToHTML("很抱歉！您申请的盈利预测表已驳回！请及时联系市场部经理；",null,null));
//                }
                updateParms.put("ProState",params.get("ProState"));
                updateParms.put("ProId",params.get("ProId"));
                updateParms.put("Reviewer",ContextUtils.getUserId());
                //修改盈利预测表
                profitMapper.updateProfit(updateParms);
                updateParms.put("OwId",params.get("OwId"));
                if(FieldCheckUtil.isMapFieldNotNull(params,new String[]{"OwState"})){
                    updateParms.put("OwState",params.get("OwState"));
                }
                //修改业主资料
                ownerMapper.UpdateOwner(params);

//                message.put("by",ContextUtils.getUserId());//操作人
//                message.put("term","2");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
//                //新增消息
//                ZuulFeign.AddMessage(message);

            }else{
                params.putAll(updateParms);
                //如果需要修改就去判断该盈利预测是完整还是简单盈利预测
                //修改盈利预测主表
                profitMapper.updateProfit(params);
                //修改盈利预测详表
                profitMapper.updateProfitInfo(params);
                //修改业主资料
                ownerMapper.UpdateOwner(params);
                if(params.get("ProType").equals(1)||params.get("ProType")=="1"){

                    //修改盈利预测招租推广费用
                    List<Map<String, Object>> ProfitLet = (List<Map<String, Object>>) params.get("ProfitLet");
                    for(Map<String, Object> let:ProfitLet){
                        let.putAll(updateParms);
                        profitMapper.updateProfitLet(let);
                    }

                    //修改盈利预测计算结果列表
                    List<Map<String, Object>> ProfitCal = (List<Map<String, Object>>) params.get("ProfitCal");
                    for(Map<String,Object> cal:ProfitCal){
                        cal.putAll(updateParms);
                        profitMapper.updateProfitCal(cal);
                    }

                    //修改盈利预测计算结果列表详情
                    List<Map<String, Object>> ProfitCalInfo = (List<Map<String, Object>>) params.get("ProfitCalInfo");
                    for(Map<String, Object> calinfo:ProfitCalInfo){
                        calinfo.putAll(updateParms);
                        profitMapper.updateProfitCalInfo(calinfo);
                    }

                    //先删除盈利预测-每年收房方式成本
                    profitMapper.delProfitCalInfo(new HashMap<String,Object>(){{
                        put("ProId",params.get("ProId"));
                    }});
                    //修改盈利预测-每年收房方式成本
                    List<Map<String, Object>> CostPerCost = (List<Map<String, Object>>) params.get("CostPerCost");
                    for(Map<String, Object> cost:CostPerCost){
//                        cost.put("ProId",params.get("ProId"));
//                        cost.putAll(updateParms);
                        cost.putAll(commonInsertParms);
                        profitMapper.AddProfitCalHou(cost);
//                        profitMapper.updateProfitHou(cost);
                    }
                }
            }

            //状态   状态   1草稿  2待审核  3驳回   4审核通过  5放弃（失效）  6房源收录草稿箱  7房源收录成功
            String ProState=params.get("ProState").toString();

            Map<String,Object>proCheck=utilsMapper.getUUID(new HashMap<String,Object>(){{
                put("uuid", "ProCheck");
                put("database", Constants.DATA_SOURCE_TCMKT);
                put("surface", "tcmkt_profit_check");
            }});
            if(proCheck!=null){
                int number=Integer.valueOf(proCheck.get("uuid").toString());
                ProCheck= ComUtils.getLocalTrmSeqNum("ylsk",number);
            }else{
                ProCheck=ComUtils.getLocalTrmSeqNum("ylsk",0);
            }
            Map<String,Object>check=new HashMap<String,Object>();
            switch (ProState){
                case "2"://重新发起审核，创建新的盈利预测审核记录。并且把最新的记录绑定到盈利预测手上
                    //盈利预测审核对象
                    check.put("ProCheck",ProCheck);
                    check.put("SubmitId",ContextUtils.getUserId());
                    check.put("SubmitTime", ConvertDateTime.getCurrentTime());
                    check.putAll(commonInsertParms);
                    //新增盈利预测审核记录
                    profitMapper.AddProfitCheck(check);
                    //把当前盈利预测审核记录标记为最新的
                    profitMapper.updateProfit(new HashMap<String,Object>(){{
                        put("ProCheck",check.get("ProCheck"));
                        put("ProId",check.get("ProId"));
                    }});
                    message.put("MeType","2");//市场部经理
                    message.put("Title","新的待审核盈利表");
                    message.put("Content", HtmlUtil.stringToHTML("注意！您有一份新的盈利预测表待审核，请及时处理！",null,null));
                    break;
                case "3"://驳回,根据盈利预测流程编号，修改当前流程的状态
                    if(FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ProCheck"})){
                        check.put("ProCheck",params.get("ProCheck"));
                        check.put("CheckId",ContextUtils.getUserId());
                        check.put("CheckTime", ConvertDateTime.getCurrentTime());
                        check.put("CheckRemarks",params.get("CheckRemarks"));
                        check.put("CheckStatus",params.get("CheckStatus"));
                        check.putAll(updateParms);
                        profitMapper.UpdateProfitCheck(check);
                        message.put("MeType","1");//收房专员
                        message.put("Title","有表单被驳回");
                        message.put("Content", HtmlUtil.stringToHTML("很抱歉！您申请的盈利预测表已驳回！请及时联系市场部经理；",null,null));
                    }
                    break;
                case "4"://通过。根据盈利预测编号和当前流程编号，修改当前流程的状态
                    if(FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ProCheck"})){
                        check.put("ProCheck",params.get("ProCheck"));
                        check.put("CheckId",ContextUtils.getUserId());
                        check.put("CheckTime", ConvertDateTime.getCurrentTime());
                        check.put("CheckStatus",params.get("CheckStatus"));
                        check.putAll(updateParms);
                        profitMapper.UpdateProfitCheck(check);
                        message.put("MeType","1");//收房专员
                        message.put("Title","有新的表单通过");
                        message.put("Content", HtmlUtil.stringToHTML("恭喜！您申请的盈利预测表已审核通过！请完成收房。",null,null));
                    }
                    break;
            }
            message.put("by",ContextUtils.getUserId());//操作人
            message.put("term","2");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
            //新增消息
            ZuulFeign.AddMessage(message);

            result=true;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return result;
    }




    /**
     * 功能描述:
     * 盈利预测待收录房源列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/11 16:14
     */
    public List<Map<String,Object>>getProfitHouList(Map<String,Object>params){
        List<Map<String,Object>>getProfitHouList=profitMapper.getProfitHouList(params);
        for(Map<String,Object> map:getProfitHouList){
            if(!StringUtils.isBlank(MapUtils.getString(map,"BuilDing"))){
                if(StringUtils.isBlank(MapUtils.getString(map,"Room"))){
                    map.put("BuilDingRoom",map.get("BuilDing").toString()+"号");
                }else{
                    map.put("BuilDingRoom",map.get("BuilDing").toString()+"号"+map.get("Room").toString()+"室");
                }
            }else{
                map.put("BuilDingRoom",null);
            }

            if(!StringUtils.isBlank(MapUtils.getString(map,"OwLoculus"))){
                if(!StringUtils.isBlank(MapUtils.getString(map,"OwHall"))){
                    if(!StringUtils.isBlank(MapUtils.getString(map,"OwGuard"))){
                        map.put("house",map.get("OwLoculus").toString()+"室"+map.get("OwHall").toString()+"厅"+map.get("OwGuard").toString()+"卫");
                    }else{
                        map.put("house",map.get("OwLoculus").toString()+"室"+map.get("OwHall").toString()+"厅");
                    }
                }else{
                    map.put("house",map.get("OwLoculus").toString()+"室");
                }
            }else{
                map.put("house",null);
            }
        }
        return getProfitHouList;
    }

    /**
     * 功能描述:
     * 盈利预测待收录房源列表总数
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/11 16:15
     */
    public Integer getProfitHouListCount(Map<String,Object>params){
        Integer getProfitHouListCount=profitMapper.getProfitHouListCount(params);
        return getProfitHouListCount;
    }

    /**
     * 楼宇号
     * @author zhoucong
     * @data 2019/8/21
     * @Param
     * @return
     */
    public List<Map<String,Object>> getOwBuilDing(Map<String,Object> params){
        return profitMapper.getOwBuilDing(params);
    }
    /**
     * 室号
     * @author zhoucong
     * @data 2019/8/21
     * @Param
     * @return
     */
    public List<Map<String,Object>> getOwRoom(Map<String,Object> params){
        return profitMapper.getOwRoom(params);
    }



    /**
     * 功能描述: 
     * 获取当前项目下的所有楼号，分组
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/25 13:58
     */
    public List<Map<String,Object>> getHousingProBuilDingList(Map<String,Object>params){
        return profitMapper.getHousingProBuilDingList(params);
    }

    /**
     * 功能描述: 
     * 获取当前项目楼号下的室号，分组
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/25 13:59
     */
    public List<Map<String,Object>>getHousingProRoomList(Map<String,Object>params){
        return profitMapper.getHousingProRoomList(params);
    }

    /**
     * 功能描述: 
     * 获取当前项目-楼号-室号下的区域，分组
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/25 14:08
     */
    public List<Map<String,Object>>getHousingConList(Map<String,Object>params){
        return profitMapper.getHousingConList(params);
    }

    /**
     * 功能描述: 
     * 根据盈利预测编号获取当前盈利预测的审批历史
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/29 14:51
     */
    public List<Map<String,Object>>getProfitCheckList(Map<String,Object>params){
        List<Map<String,Object>>getProfitCheckList=profitMapper.getProfitCheckList(params);
        for(Map<String,Object> map:getProfitCheckList){

            if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"SubmitId"})){
                //提交盈利预测人员
                JsonResult jsonResult1=ZuulFeign.getUserMap(new HashMap<String,Object>(){{
                    put("UserId",map.get("SubmitId"));
                }});
                Map<String,Object>Submit=(Map<String,Object>)jsonResult1.getResult();
                map.put("SubmitName",Submit.get("UserName"));
            }else{
                map.put("SubmitName",null);
            }

            if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"CheckId"})){
                //审核盈利预测人员
                JsonResult jsonResult2=ZuulFeign.getUserMap(new HashMap<String,Object>(){{
                    put("UserId",map.get("CheckId"));
                }});
                Map<String,Object>Check=(Map<String,Object>)jsonResult2.getResult();
                map.put("CheckName",Check.get("UserName"));
            }else{
                map.put("CheckName",null);
            }
        }
        return getProfitCheckList;
    }

    /**
     * 功能描述: 
     * 根据盈利预测编号获取当前盈利预测的审批历史总数
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/29 14:52
     */
    public Integer getProfitCheckListCount(Map<String,Object>params){
        return profitMapper.getProfitCheckListCount(params);
    }

    /**
     * 功能描述:
     * 根据项目编号集合获取盈利预测所有楼号
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/20 19:36
     */
    public List<Map<String,Object>>getComIdByProBuiList(Map<String,Object>params){
        List<Map<String,Object>>getComIdByProBuiList=profitMapper.getComIdByProBuiList(params);
        if(getComIdByProBuiList.size()>0){
            List<String>getComIdByProBuiLists;
            for(Map<String,Object> map:getComIdByProBuiList){
                getComIdByProBuiLists=profitMapper.getComIdByProBuiLists(new HashMap<String,Object>(){{
                    put("Building",map.get("buiId"));
                }});
                if(getComIdByProBuiLists.size()>0){
                    map.put("HouList",getComIdByProBuiLists);
                }else{
                    map.put("HouList",new ArrayList<String>());
                }

            }
        }

        return getComIdByProBuiList;
    }

    /**
     * 功能描述:
     * 根据项目编号集合和楼号集合获取盈利预测所有室号
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/20 19:36
     */
    public List<Map<String,Object>>getComIdAndBuiProRoomList(Map<String,Object>params){
        return profitMapper.getComIdAndBuiProRoomList(params);
    }

}
